package board;

import java.awt.Point;

import sgf.SGFParseException;
import sgf.SGFUtils;

/**
 * Represents a label on the Board.
 * @author TKington
 *
 */
public class NodeLabel extends SimpleMark {
	/** The label text. */
    private String label;
    
    /**
     * Creates a new NodeLabel.
     * @param s the label text
     * @param p the Point
     * @throws SGFParseException if the point is off the board
     */
    public NodeLabel(String s, Point p) throws SGFParseException {
        super(LABEL, p);
        
        SGFUtils.checkPoint(p, 19);
        
        //  Remove leading 0's from numbers
        try {
            int i = Integer.parseInt(s);
            label = String.valueOf(i);
        }
        catch(NumberFormatException e) {
            label = s;
        }
    }
    
    @Override
	public Object clone() {
    	try {
    		return new NodeLabel(label, new Point(pt));
    	}
    	catch(SGFParseException e) {
    		return null;
    	}
    }
    
    @Override
	public boolean equals(Object o) {
        if(!(o instanceof NodeLabel))
            return false;
        
        NodeLabel l = (NodeLabel)o;
        if(!pt.equals(l.pt))
            return false;
        if(!label.equals(l.label))
            return false;
        return true;
    }
    
    /**
     * Returns the text of the label.
     * @return the text of the label
     */
    public String getText() { return label; }
}
